//
//  UIButton+Extension.swift
//  WeiBo
//
//  Created by apple on 16/6/27.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

extension UIButton{
    
    convenience init(title: String,image: String,textColor: UIColor){
        
        // 
        self.init()
        
        self.setTitle(title, forState: .Normal)
        
        self.setImage(UIImage(named: image), forState: .Normal)
        
        self.setTitleColor(textColor, forState: .Normal)
        
    }
    
    convenience init(imageName: String,action: String?,target: AnyObject){
        
        self.init()
        
        self.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        self.setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        
        if let oAction = action {
            // 注意: target 千万不要写 self
           self.addTarget(target, action: Selector(oAction), forControlEvents: UIControlEvents.TouchUpInside)
        }
        
        self.sizeToFit()
        
        
    }
    
}
